home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / lib / python2.6 / uuid.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-11-11  |  21KB  |  610 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. """UUID objects (universally unique identifiers) according to RFC 4122.
  5.  
  6. This module provides immutable UUID objects (class UUID) and the functions
  7. uuid1(), uuid3(), uuid4(), uuid5() for generating version 1, 3, 4, and 5
  8. UUIDs as specified in RFC 4122.
  9.  
  10. If all you want is a unique ID, you should probably call uuid1() or uuid4().
  11. Note that uuid1() may compromise privacy since it creates a UUID containing
  12. the computer's network address.  uuid4() creates a random UUID.
  13.  
  14. Typical usage:
  15.  
  16.     >>> import uuid
  17.  
  18.     # make a UUID based on the host ID and current time
  19.     >>> uuid.uuid1()
  20.     UUID('a8098c1a-f86e-11da-bd1a-00112444be1e')
  21.  
  22.     # make a UUID using an MD5 hash of a namespace UUID and a name
  23.     >>> uuid.uuid3(uuid.NAMESPACE_DNS, 'python.org')
  24.     UUID('6fa459ea-ee8a-3ca4-894e-db77e160355e')
  25.  
  26.     # make a random UUID
  27.     >>> uuid.uuid4()
  28.     UUID('16fd2706-8baf-433b-82eb-8c7fada847da')
  29.  
  30.     # make a UUID using a SHA-1 hash of a namespace UUID and a name
  31.     >>> uuid.uuid5(uuid.NAMESPACE_DNS, 'python.org')
  32.     UUID('886313e1-3b8a-5372-9b90-0c9aee199e5d')
  33.  
  34.     # make a UUID from a string of hex digits (braces and hyphens ignored)
  35.     >>> x = uuid.UUID('{00010203-0405-0607-0809-0a0b0c0d0e0f}')
  36.  
  37.     # convert a UUID to a string of hex digits in standard form
  38.     >>> str(x)
  39.     '00010203-0405-0607-0809-0a0b0c0d0e0f'
  40.  
  41.     # get the raw 16 bytes of the UUID
  42.     >>> x.bytes
  43.     '\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\t\\n\\x0b\\x0c\\r\\x0e\\x0f'
  44.  
  45.     # make a UUID from a 16-byte string
  46.     >>> uuid.UUID(bytes=x.bytes)
  47.     UUID('00010203-0405-0607-0809-0a0b0c0d0e0f')
  48. """
  49. __author__ = 'Ka-Ping Yee <ping@zesty.ca>'
  50. (RESERVED_NCS, RFC_4122, RESERVED_MICROSOFT, RESERVED_FUTURE) = [
  51.     'reserved for NCS compatibility',
  52.     'specified in RFC 4122',
  53.     'reserved for Microsoft compatibility',
  54.     'reserved for future definition']
  55.  
  56. class UUID(object):
  57.     """Instances of the UUID class represent UUIDs as specified in RFC 4122.
  58.     UUID objects are immutable, hashable, and usable as dictionary keys.
  59.     Converting a UUID to a string with str() yields something in the form
  60.     '12345678-1234-1234-1234-123456789abc'.  The UUID constructor accepts
  61.     five possible forms: a similar string of hexadecimal digits, or a tuple
  62.     of six integer fields (with 32-bit, 16-bit, 16-bit, 8-bit, 8-bit, and
  63.     48-bit values respectively) as an argument named 'fields', or a string
  64.     of 16 bytes (with all the integer fields in big-endian order) as an
  65.     argument named 'bytes', or a string of 16 bytes (with the first three
  66.     fields in little-endian order) as an argument named 'bytes_le', or a
  67.     single 128-bit integer as an argument named 'int'.
  68.  
  69.     UUIDs have these read-only attributes:
  70.  
  71.         bytes       the UUID as a 16-byte string (containing the six
  72.                     integer fields in big-endian byte order)
  73.  
  74.         bytes_le    the UUID as a 16-byte string (with time_low, time_mid,
  75.                     and time_hi_version in little-endian byte order)
  76.  
  77.         fields      a tuple of the six integer fields of the UUID,
  78.                     which are also available as six individual attributes
  79.                     and two derived attributes:
  80.  
  81.             time_low                the first 32 bits of the UUID
  82.             time_mid                the next 16 bits of the UUID
  83.             time_hi_version         the next 16 bits of the UUID
  84.             clock_seq_hi_variant    the next 8 bits of the UUID
  85.             clock_seq_low           the next 8 bits of the UUID
  86.             node                    the last 48 bits of the UUID
  87.  
  88.             time                    the 60-bit timestamp
  89.             clock_seq               the 14-bit sequence number
  90.  
  91.         hex         the UUID as a 32-character hexadecimal string
  92.  
  93.         int         the UUID as a 128-bit integer
  94.  
  95.         urn         the UUID as a URN as specified in RFC 4122
  96.  
  97.         variant     the UUID variant (one of the constants RESERVED_NCS,
  98.                     RFC_4122, RESERVED_MICROSOFT, or RESERVED_FUTURE)
  99.  
  100.         version     the UUID version number (1 through 5, meaningful only
  101.                     when the variant is RFC_4122)
  102.     """
  103.     
  104.     def __init__(self, hex = None, bytes = None, bytes_le = None, fields = None, int = None, version = None):
  105.         """Create a UUID from either a string of 32 hexadecimal digits,
  106.         a string of 16 bytes as the 'bytes' argument, a string of 16 bytes
  107.         in little-endian order as the 'bytes_le' argument, a tuple of six
  108.         integers (32-bit time_low, 16-bit time_mid, 16-bit time_hi_version,
  109.         8-bit clock_seq_hi_variant, 8-bit clock_seq_low, 48-bit node) as
  110.         the 'fields' argument, or a single 128-bit integer as the 'int'
  111.         argument.  When a string of hex digits is given, curly braces,
  112.         hyphens, and a URN prefix are all optional.  For example, these
  113.         expressions all yield the same UUID:
  114.  
  115.         UUID('{12345678-1234-5678-1234-567812345678}')
  116.         UUID('12345678123456781234567812345678')
  117.         UUID('urn:uuid:12345678-1234-5678-1234-567812345678')
  118.         UUID(bytes='\\x12\\x34\\x56\\x78'*4)
  119.         UUID(bytes_le='\\x78\\x56\\x34\\x12\\x34\\x12\\x78\\x56' +
  120.                       '\\x12\\x34\\x56\\x78\\x12\\x34\\x56\\x78')
  121.         UUID(fields=(0x12345678, 0x1234, 0x5678, 0x12, 0x34, 0x567812345678))
  122.         UUID(int=0x12345678123456781234567812345678)
  123.  
  124.         Exactly one of 'hex', 'bytes', 'bytes_le', 'fields', or 'int' must
  125.         be given.  The 'version' argument is optional; if given, the resulting
  126.         UUID will have its variant and version set according to RFC 4122,
  127.         overriding the given 'hex', 'bytes', 'bytes_le', 'fields', or 'int'.
  128.         """
  129.         if [
  130.             hex,
  131.             bytes,
  132.             bytes_le,
  133.             fields,
  134.             int].count(None) != 4:
  135.             raise TypeError('need one of hex, bytes, bytes_le, fields, or int')
  136.         [
  137.             hex,
  138.             bytes,
  139.             bytes_le,
  140.             fields,
  141.             int].count(None) != 4
  142.         if hex is not None:
  143.             hex = hex.replace('urn:', '').replace('uuid:', '')
  144.             hex = hex.strip('{}').replace('-', '')
  145.             if len(hex) != 32:
  146.                 raise ValueError('badly formed hexadecimal UUID string')
  147.             len(hex) != 32
  148.             int = long(hex, 16)
  149.         
  150.         if bytes_le is not None:
  151.             if len(bytes_le) != 16:
  152.                 raise ValueError('bytes_le is not a 16-char string')
  153.             len(bytes_le) != 16
  154.             bytes = bytes_le[3] + bytes_le[2] + bytes_le[1] + bytes_le[0] + bytes_le[5] + bytes_le[4] + bytes_le[7] + bytes_le[6] + bytes_le[8:]
  155.         
  156.         if bytes is not None:
  157.             if len(bytes) != 16:
  158.                 raise ValueError('bytes is not a 16-char string')
  159.             len(bytes) != 16
  160.             int = long('%02x' * 16 % tuple(map(ord, bytes)), 16)
  161.         
  162.         if fields is not None:
  163.             if len(fields) != 6:
  164.                 raise ValueError('fields is not a 6-tuple')
  165.             len(fields) != 6
  166.             (time_low, time_mid, time_hi_version, clock_seq_hi_variant, clock_seq_low, node) = fields
  167.             if time_low <= time_low:
  168.                 pass
  169.             elif not time_low < 0x100000000L:
  170.                 raise ValueError('field 1 out of range (need a 32-bit value)')
  171.             
  172.             if time_mid <= time_mid:
  173.                 pass
  174.             elif not time_mid < 0x10000L:
  175.                 raise ValueError('field 2 out of range (need a 16-bit value)')
  176.             
  177.             if time_hi_version <= time_hi_version:
  178.                 pass
  179.             elif not time_hi_version < 0x10000L:
  180.                 raise ValueError('field 3 out of range (need a 16-bit value)')
  181.             
  182.             if clock_seq_hi_variant <= clock_seq_hi_variant:
  183.                 pass
  184.             elif not clock_seq_hi_variant < 0x100L:
  185.                 raise ValueError('field 4 out of range (need an 8-bit value)')
  186.             
  187.             if clock_seq_low <= clock_seq_low:
  188.                 pass
  189.             elif not clock_seq_low < 0x100L:
  190.                 raise ValueError('field 5 out of range (need an 8-bit value)')
  191.             
  192.             if node <= node:
  193.                 pass
  194.             elif not node < 0x1000000000000L:
  195.                 raise ValueError('field 6 out of range (need a 48-bit value)')
  196.             
  197.             clock_seq = clock_seq_hi_variant << 0x8L | clock_seq_low
  198.             int = time_low << 0x60L | time_mid << 0x50L | time_hi_version << 0x40L | clock_seq << 0x30L | node
  199.         
  200.         if int is not None:
  201.             if int <= int:
  202.                 pass
  203.             elif not int < 0x100000000000000000000000000000000L:
  204.                 raise ValueError('int is out of range (need a 128-bit value)')
  205.             
  206.         
  207.         if version is not None:
  208.             if version <= version:
  209.                 pass
  210.             elif not version <= 5:
  211.                 raise ValueError('illegal version number')
  212.             
  213.             int &= -0xC000000000000001L
  214.             int |= 0x8000000000000000L
  215.             int &= -0xF0000000000000000001L
  216.             int |= version << 0x4CL
  217.         
  218.         self.__dict__['int'] = int
  219.  
  220.     
  221.     def __cmp__(self, other):
  222.         if isinstance(other, UUID):
  223.             return cmp(self.int, other.int)
  224.         return NotImplemented
  225.  
  226.     
  227.     def __hash__(self):
  228.         return hash(self.int)
  229.  
  230.     
  231.     def __int__(self):
  232.         return self.int
  233.  
  234.     
  235.     def __repr__(self):
  236.         return 'UUID(%r)' % str(self)
  237.  
  238.     
  239.     def __setattr__(self, name, value):
  240.         raise TypeError('UUID objects are immutable')
  241.  
  242.     
  243.     def __str__(self):
  244.         hex = '%032x' % self.int
  245.         return '%s-%s-%s-%s-%s' % (hex[:8], hex[8:12], hex[12:16], hex[16:20], hex[20:])
  246.  
  247.     
  248.     def get_bytes(self):
  249.         bytes = ''
  250.         for shift in range(0, 128, 8):
  251.             bytes = chr(self.int >> shift & 255) + bytes
  252.         
  253.         return bytes
  254.  
  255.     bytes = property(get_bytes)
  256.     
  257.     def get_bytes_le(self):
  258.         bytes = self.bytes
  259.         return bytes[3] + bytes[2] + bytes[1] + bytes[0] + bytes[5] + bytes[4] + bytes[7] + bytes[6] + bytes[8:]
  260.  
  261.     bytes_le = property(get_bytes_le)
  262.     
  263.     def get_fields(self):
  264.         return (self.time_low, self.time_mid, self.time_hi_version, self.clock_seq_hi_variant, self.clock_seq_low, self.node)
  265.  
  266.     fields = property(get_fields)
  267.     
  268.     def get_time_low(self):
  269.         return self.int >> 0x60L
  270.  
  271.     time_low = property(get_time_low)
  272.     
  273.     def get_time_mid(self):
  274.         return self.int >> 0x50L & 65535
  275.  
  276.     time_mid = property(get_time_mid)
  277.     
  278.     def get_time_hi_version(self):
  279.         return self.int >> 0x40L & 65535
  280.  
  281.     time_hi_version = property(get_time_hi_version)
  282.     
  283.     def get_clock_seq_hi_variant(self):
  284.         return self.int >> 0x38L & 255
  285.  
  286.     clock_seq_hi_variant = property(get_clock_seq_hi_variant)
  287.     
  288.     def get_clock_seq_low(self):
  289.         return self.int >> 0x30L & 255
  290.  
  291.     clock_seq_low = property(get_clock_seq_low)
  292.     
  293.     def get_time(self):
  294.         return (self.time_hi_version & 0xFFFL) << 0x30L | self.time_mid << 0x20L | self.time_low
  295.  
  296.     time = property(get_time)
  297.     
  298.     def get_clock_seq(self):
  299.         return (self.clock_seq_hi_variant & 0x3FL) << 0x8L | self.clock_seq_low
  300.  
  301.     clock_seq = property(get_clock_seq)
  302.     
  303.     def get_node(self):
  304.         return self.int & 0xFFFFFFFFFFFFL
  305.  
  306.     node = property(get_node)
  307.     
  308.     def get_hex(self):
  309.         return '%032x' % self.int
  310.  
  311.     hex = property(get_hex)
  312.     
  313.     def get_urn(self):
  314.         return 'urn:uuid:' + str(self)
  315.  
  316.     urn = property(get_urn)
  317.     
  318.     def get_variant(self):
  319.         if not self.int & 0x8000000000000000L:
  320.             return RESERVED_NCS
  321.         if not self.int & 0x4000000000000000L:
  322.             return RFC_4122
  323.         if not self.int & 0x2000000000000000L:
  324.             return RESERVED_MICROSOFT
  325.         return RESERVED_FUTURE
  326.  
  327.     variant = property(get_variant)
  328.     
  329.     def get_version(self):
  330.         if self.variant == RFC_4122:
  331.             return int(self.int >> 0x4CL & 15)
  332.  
  333.     version = property(get_version)
  334.  
  335.  
  336. def _find_mac(command, args, hw_identifiers, get_index):
  337.     import os as os
  338.     for dir in [
  339.         '',
  340.         '/sbin/',
  341.         '/usr/sbin']:
  342.         executable = os.path.join(dir, command)
  343.         if not os.path.exists(executable):
  344.             continue
  345.         
  346.         
  347.         try:
  348.             cmd = 'LC_ALL=C %s %s 2>/dev/null' % (executable, args)
  349.             pipe = os.popen(cmd)
  350.         except IOError:
  351.             continue
  352.  
  353.         for line in pipe:
  354.             words = line.lower().split()
  355.             for i in range(len(words)):
  356.                 if words[i] in hw_identifiers:
  357.                     return int(words[get_index(i)].replace(':', ''), 16)
  358.             
  359.         
  360.     
  361.  
  362.  
  363. def _ifconfig_getnode():
  364.     '''Get the hardware address on Unix by running ifconfig.'''
  365.     for args in ('', '-a', '-av'):
  366.         mac = _find_mac('ifconfig', args, [
  367.             'hwaddr',
  368.             'ether'], (lambda i: i + 1))
  369.         if mac:
  370.             return mac
  371.     
  372.     import socket as socket
  373.     ip_addr = socket.gethostbyname(socket.gethostname())
  374.     mac = _find_mac('arp', '-an', [
  375.         ip_addr], (lambda i: -1))
  376.     if mac:
  377.         return mac
  378.     mac = _find_mac('lanscan', '-ai', [
  379.         'lan0'], (lambda i: 0))
  380.     if mac:
  381.         return mac
  382.  
  383.  
  384. def _ipconfig_getnode():
  385.     '''Get the hardware address on Windows by running ipconfig.exe.'''
  386.     import os
  387.     import re as re
  388.     dirs = [
  389.         '',
  390.         'c:\\windows\\system32',
  391.         'c:\\winnt\\system32']
  392.     
  393.     try:
  394.         import ctypes as ctypes
  395.         buffer = ctypes.create_string_buffer(300)
  396.         ctypes.windll.kernel32.GetSystemDirectoryA(buffer, 300)
  397.         dirs.insert(0, buffer.value.decode('mbcs'))
  398.     except:
  399.         pass
  400.  
  401.     for dir in dirs:
  402.         
  403.         try:
  404.             pipe = os.popen(os.path.join(dir, 'ipconfig') + ' /all')
  405.         except IOError:
  406.             continue
  407.  
  408.         for line in pipe:
  409.             value = line.split(':')[-1].strip().lower()
  410.             if re.match('([0-9a-f][0-9a-f]-){5}[0-9a-f][0-9a-f]', value):
  411.                 return int(value.replace('-', ''), 16)
  412.         
  413.     
  414.  
  415.  
  416. def _netbios_getnode():
  417.     '''Get the hardware address on Windows using NetBIOS calls.
  418.     See http://support.microsoft.com/kb/118623 for details.'''
  419.     import win32wnet as win32wnet
  420.     import netbios as netbios
  421.     ncb = netbios.NCB()
  422.     ncb.Command = netbios.NCBENUM
  423.     ncb.Buffer = adapters = netbios.LANA_ENUM()
  424.     adapters._pack()
  425.     if win32wnet.Netbios(ncb) != 0:
  426.         return None
  427.     adapters._unpack()
  428.     for i in range(adapters.length):
  429.         ncb.Reset()
  430.         ncb.Command = netbios.NCBRESET
  431.         ncb.Lana_num = ord(adapters.lana[i])
  432.         if win32wnet.Netbios(ncb) != 0:
  433.             continue
  434.         
  435.         ncb.Reset()
  436.         ncb.Command = netbios.NCBASTAT
  437.         ncb.Lana_num = ord(adapters.lana[i])
  438.         ncb.Callname = '*'.ljust(16)
  439.         ncb.Buffer = status = netbios.ADAPTER_STATUS()
  440.         if win32wnet.Netbios(ncb) != 0:
  441.             continue
  442.         
  443.         status._unpack()
  444.         bytes = map(ord, status.adapter_address)
  445.         return (bytes[0] << 0x28L) + (bytes[1] << 0x20L) + (bytes[2] << 0x18L) + (bytes[3] << 0x10L) + (bytes[4] << 0x8L) + bytes[5]
  446.     
  447.  
  448. _uuid_generate_random = None
  449. _uuid_generate_time = None
  450. _UuidCreate = None
  451.  
  452. try:
  453.     import ctypes
  454.     import ctypes.util as ctypes
  455.     for libname in [
  456.         'uuid',
  457.         'c']:
  458.         
  459.         try:
  460.             lib = ctypes.CDLL(ctypes.util.find_library(libname))
  461.         except:
  462.             continue
  463.  
  464.         if hasattr(lib, 'uuid_generate_random'):
  465.             _uuid_generate_random = lib.uuid_generate_random
  466.         
  467.         if hasattr(lib, 'uuid_generate_time'):
  468.             _uuid_generate_time = lib.uuid_generate_time
  469.             continue
  470.     
  471.     
  472.     try:
  473.         lib = ctypes.windll.rpcrt4
  474.     except:
  475.         lib = None
  476.  
  477.     _UuidCreate = getattr(lib, 'UuidCreateSequential', getattr(lib, 'UuidCreate', None))
  478. except:
  479.     pass
  480.  
  481.  
  482. def _unixdll_getnode():
  483.     '''Get the hardware address on Unix using ctypes.'''
  484.     _buffer = ctypes.create_string_buffer(16)
  485.     _uuid_generate_time(_buffer)
  486.     return UUID(bytes = _buffer.raw).node
  487.  
  488.  
  489. def _windll_getnode():
  490.     '''Get the hardware address on Windows using ctypes.'''
  491.     _buffer = ctypes.create_string_buffer(16)
  492.     if _UuidCreate(_buffer) == 0:
  493.         return UUID(bytes = _buffer.raw).node
  494.  
  495.  
  496. def _random_getnode():
  497.     '''Get a random node ID, with eighth bit set as suggested by RFC 4122.'''
  498.     import random as random
  499.     return random.randrange(0, 0x1000000000000L) | 0x10000000000L
  500.  
  501. _node = None
  502.  
  503. def getnode():
  504.     '''Get the hardware address as a 48-bit positive integer.
  505.  
  506.     The first time this runs, it may launch a separate program, which could
  507.     be quite slow.  If all attempts to obtain the hardware address fail, we
  508.     choose a random 48-bit number with its eighth bit set to 1 as recommended
  509.     in RFC 4122.
  510.     '''
  511.     global _node
  512.     if _node is not None:
  513.         return _node
  514.     import sys as sys
  515.     if sys.platform == 'win32':
  516.         getters = [
  517.             _windll_getnode,
  518.             _netbios_getnode,
  519.             _ipconfig_getnode]
  520.     else:
  521.         getters = [
  522.             _unixdll_getnode,
  523.             _ifconfig_getnode]
  524.     for getter in getters + [
  525.         _random_getnode]:
  526.         
  527.         try:
  528.             _node = getter()
  529.         except:
  530.             continue
  531.  
  532.         if _node is not None:
  533.             return _node
  534.     
  535.  
  536. _last_timestamp = None
  537.  
  538. def uuid1(node = None, clock_seq = None):
  539.     """Generate a UUID from a host ID, sequence number, and the current time.
  540.     If 'node' is not given, getnode() is used to obtain the hardware
  541.     address.  If 'clock_seq' is given, it is used as the sequence number;
  542.     otherwise a random 14-bit sequence number is chosen."""
  543.     global _last_timestamp
  544.     if _uuid_generate_time:
  545.         if clock_seq is clock_seq:
  546.             pass
  547.         elif clock_seq is None:
  548.             _buffer = ctypes.create_string_buffer(16)
  549.             _uuid_generate_time(_buffer)
  550.             return UUID(bytes = _buffer.raw)
  551.     import time
  552.     nanoseconds = int(time.time() * 1e+09)
  553.     timestamp = int(nanoseconds / 100) + 0x1B21DD213814000L
  554.     if timestamp <= _last_timestamp:
  555.         timestamp = _last_timestamp + 1
  556.     
  557.     _last_timestamp = timestamp
  558.     if clock_seq is None:
  559.         import random
  560.         clock_seq = random.randrange(0x4000L)
  561.     
  562.     time_low = timestamp & 0xFFFFFFFFL
  563.     time_mid = timestamp >> 0x20L & 0xFFFFL
  564.     time_hi_version = timestamp >> 0x30L & 0xFFFL
  565.     clock_seq_low = clock_seq & 0xFFL
  566.     clock_seq_hi_variant = clock_seq >> 0x8L & 0x3FL
  567.     if node is None:
  568.         node = getnode()
  569.     
  570.     return UUID(fields = (time_low, time_mid, time_hi_version, clock_seq_hi_variant, clock_seq_low, node), version = 1)
  571.  
  572.  
  573. def uuid3(namespace, name):
  574.     '''Generate a UUID from the MD5 hash of a namespace UUID and a name.'''
  575.     md5 = md5
  576.     import hashlib
  577.     hash = md5(namespace.bytes + name).digest()
  578.     return UUID(bytes = hash[:16], version = 3)
  579.  
  580.  
  581. def uuid4():
  582.     '''Generate a random UUID.'''
  583.     if _uuid_generate_random:
  584.         _buffer = ctypes.create_string_buffer(16)
  585.         _uuid_generate_random(_buffer)
  586.         return UUID(bytes = _buffer.raw)
  587.     
  588.     try:
  589.         import os
  590.         return UUID(bytes = os.urandom(16), version = 4)
  591.     except:
  592.         _uuid_generate_random
  593.         import random
  594.         bytes = [ chr(random.randrange(256)) for i in range(16) ]
  595.         return UUID(bytes = bytes, version = 4)
  596.  
  597.  
  598.  
  599. def uuid5(namespace, name):
  600.     '''Generate a UUID from the SHA-1 hash of a namespace UUID and a name.'''
  601.     sha1 = sha1
  602.     import hashlib
  603.     hash = sha1(namespace.bytes + name).digest()
  604.     return UUID(bytes = hash[:16], version = 5)
  605.  
  606. NAMESPACE_DNS = UUID('6ba7b810-9dad-11d1-80b4-00c04fd430c8')
  607. NAMESPACE_URL = UUID('6ba7b811-9dad-11d1-80b4-00c04fd430c8')
  608. NAMESPACE_OID = UUID('6ba7b812-9dad-11d1-80b4-00c04fd430c8')
  609. NAMESPACE_X500 = UUID('6ba7b814-9dad-11d1-80b4-00c04fd430c8')
  610.